package com.hot100.mid;

import java.util.Stack;

/**
 * @author zhengTao
 * @version 1.0
 * @description: 最大连续字串乘积(记录最大值，同时也要记录最小值)
 * @date 2022/9/3 17:02
 */
public class Demo35 {
    public static void main(String[] args) {
        int[] nums={-2,3,-4};
        int i = maxProduct(nums);
        System.out.println(i);
    }
    public static int maxProduct(int[] nums) {
          if(nums.length<=0){
              return 0;
          }
        int max=nums[0];
        int min=nums[0];
        int[] maxResult=new int[nums.length];
        int[] minResult=new int[nums.length];
        maxResult[0]=max;
        minResult[0]=min;
        for (int i = 1; i < nums.length; i++) {
            maxResult[i]=Math.max(maxResult[i-1]*nums[i],Math.max(minResult[i-1]*nums[i],nums[i]));
            max=Math.max(max,maxResult[i]);
            minResult[i]=Math.min(minResult[i-1]*nums[i],Math.min(maxResult[i-1]*nums[i],nums[i]));
            min=Math.min(min,minResult[i]);

        }
        return max;
    }
}
